import Vue from 'vue'
import Router from 'vue-router'

const Login = () =>
    import ('@/components/login');



// 防止重复点击报错
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
};
Vue.use(Router);
const routes = [{
        path: '/login',
        name: 'login',
        component: Login,
    },
    {
        path: '/',
        redirect: "/login"
    },
    {
        path: '/index',
        name: 'index',
        component: () =>
            import ( /* webpackChunkName: "index" */ '@/components/index.vue'),
        children: [{
                path: 'survey',
                name: 'survey',
                component: () =>
                    import ( /* webpackChunkName: "survey" */ '@/components/survey/survey.vue'),
            },
            {
                path: 'commodity',
                name: 'commodity',
                component: () =>
                    import ( /* webpackChunkName: "commodity" */ '@/components/commodity/commodity.vue'),
                children: [{
                        path: 'home',
                        name: 'home',
                        component: () =>
                            import ( /* webpackChunkName: "home" */ '@/components/commodity/home.vue'),
                        meta: {
                            keepAlive: true
                        }
                    },
                    {
                        path: 'classify',
                        name: 'classify',
                        component: () =>
                            import ( /* webpackChunkName: "classify" */ '@/components/commodity/classify.vue'),
                    },
                    {
                        path: 'detail',
                        name: 'detail',
                        component: () =>
                            import ( /* webpackChunkName: "detail" */ '@/components/commodity/detail.vue'),
                    },
                    {
                        path: 'topic',
                        name: 'topic',
                        component: () =>
                            import ( /* webpackChunkName: "topic" */ '@/components/commodity/topic.vue'),
                    },
                    {
                        path: 'searchResult',
                        name: 'searchResult',
                        component: () =>
                            import ( /* webpackChunkName: "searchResult" */ '@/components/commodity/searchResult.vue'),
                    },
                    {
                        path: 'discounts',
                        name: 'discounts',
                        component: () =>
                            import ( /* webpackChunkName: "discounts" */ '@/components/commodity/discounts.vue'),
                    }
                ]
            },
            {
                path: 'orderCheck',
                name: "orderCheck",
                component: () =>
                    import ( /* webpackChunkName: "orderCheck" */ '@/components/order/orderCheck.vue')
            },
            {
                path: 'order',
                name: 'order',
                component: () =>
                    import ( /* webpackChunkName: "order" */ '@/components/order/order.vue'),
                children: [{
                        path: 'balance',
                        name: 'balance',
                        component: () =>
                            import ( /* webpackChunkName: "balance" */ '@/components/order/balance.vue'),
                    },
                    {
                        path: 'allOrder',
                        name: 'allOrder',
                        component: () =>
                            import ( /* webpackChunkName: "allOrder" */ '@/components/order/allOrder.vue'),
                    }, {
                        path: 'abnormalOrder',
                        name: 'abnormalOrder',
                        component: () =>
                            import ( /* webpackChunkName: "abnormalOrder" */ '@/components/order/abnormalOrder.vue'),
                    }, {
                        path: 'serviceOrder',
                        name: 'serviceOrder',
                        component: () =>
                            import ( /* webpackChunkName: "serviceOrder" */ '@/components/order/serviceOrder.vue'),
                    }, {
                        path: 'orderDetails',
                        name: 'orderDetails',
                        component: () =>
                            import ( /* webpackChunkName: "orderDetails" */ '@/components/order/orderDetails.vue'),
                    }, {
                        path: 'abnormalDetails',
                        name: 'abnormalDetails',
                        component: () =>
                            import ( /* webpackChunkName: "abnormalDetails" */ '@/components/order/abnormalDetails.vue'),
                    }, {
                        path: 'serviceDetails',
                        name: 'serviceDetails',
                        component: () =>
                            import ( /* webpackChunkName: "serviceDetails" */ '@/components/order/serviceDetails.vue'),
                    }, {
                        path: 'apply',
                        name: 'apply',
                        component: () =>
                            import ( /* webpackChunkName: "apply" */ '@/components/order/apply.vue'),
                    }, {
                        path: 'applyDetails',
                        name: 'applyDetails',
                        component: () =>
                            import ( /* webpackChunkName: "applyDetails" */ '@/components/order/applyDetails.vue'),
                    },

                ]
            },

            {
                path: 'buyer',
                name: 'buyer',
                component: () =>
                    import ( /* webpackChunkName: "buyer" */ '@/components/buyer/index.vue'),
                children: [{
                    path: 'mall/helpCenter',
                    name: 'mall/helpCenter',
                    component: () =>
                        import ( /* webpackChunkName: "mall/helpCenter" */ '@/components/buyer/mall/helpCenter.vue'),
                }, ]
            },
            //官网相关的页面
            {
                path: 'website',
                name: 'website',
                component: () =>
                    import ( /* webpackChunkName: "website" */ '@/components/website/website.vue'),
                children: [{
                    path: 'home',
                    name: 'home',
                    component: () =>
                        import ( /* webpackChunkName: "home" */ '@/components/website/home.vue'),
                }, {
                    path: 'service',
                    name: 'service',
                    component: () =>
                        import ( /* webpackChunkName: "service" */ '@/components/website/service.vue'),
                }, {
                    path: 'cooperate',
                    name: 'cooperate',
                    component: () =>
                        import ( /* webpackChunkName: "cooperate" */ '@/components/website/cooperate.vue'),
                }, {
                    path: 'about',
                    name: 'about',
                    component: () =>
                        import ( /* webpackChunkName: "about" */ '@/components/website/about.vue'),
                }, ]
            },
            // {
            //     path: 'home',
            //     name: 'home',
            //     component: () =>
            //         import ( /* webpackChunkName: "home" */ '@/components/website/home.vue'),
            //     // children: [{
            //     //     path: 'home',
            //     //     name: 'home',
            //     //     component: () =>
            //     //         import ( /* webpackChunkName: "home" */ '@/components/website/home.vue'),
            //     // }, ]
            // },







            {
                path: 'confirm',
                name: 'confirm',
                component: () =>
                    import ( /* webpackChunkName: "confirm" */ '@/components/order/confirm.vue'),
            },

            {
                path: 'result',
                name: 'result',
                component: () =>
                    import ( /* webpackChunkName: "result" */ '@/components/order/result.vue'),
            },
            {
                path: 'payment',
                name: 'payment',
                component: () =>
                    import ( /* webpackChunkName: "payment" */ '@/components/order/payment.vue'),
            },
            {
                path: "shoppingTrolley",
                name: "shoppingTrolley",
                component: () =>
                    import ( /* webpackChunkName: "shoppingTrolley" */ '@/components/order/shoppingTrolley.vue')
            },
            {
                path: 'shop',
                name: 'shop',
                component: () =>
                    import ( /* webpackChunkName: "shop" */ '@/components/shop/shop.vue'),
                children: [{
                        path: "fundsManagement",
                        name: "fundsManagement",
                        component: () =>
                            import ( /* webpackChunkName: "shop" */ '@/components/shop/fundsManagement.vue')
                    },
                    {
                        path: "customerManagement",
                        name: "customerManagement",
                        component: () =>
                            import ( /* webpackChunkName: "shop" */ '@/components/shop/customerManagement.vue')
                    }
                ]
            },
            {
                path: 'setting',
                name: 'setting',
                component: () =>
                    import ( /* webpackChunkName: "setting" */ '@/components/setting/setting.vue'),
                children: [{
                    path: "information",
                    name: "information",
                    component: () =>
                        import ( /* webpackChunkName: "setting" */ '@/components/setting/information.vue')
                }]
            },
            {
                path: 'play',
                name: 'play',
                component: () =>
                    import ( /* webpackChunkName: "play" */ '@/components/play/play.vue'),
            },
            {
                path: "verify",
                name: "verify",
                component: () =>
                    import ( /* webpackChunkName: "verify" */ '@/components/play/verify.vue')
            },

        ]
    },

    {
        path: '*',
        name: "404",
        component: () =>
            import ( /* webpackChunkName: "404" */ '@/components/404.vue')
    },
]
export default new Router({
    // mode:'history',
    routes,
    scrollBehavior(to, from, saveTop) {
        if (saveTop) {
            return saveTop;
        } else {
            return { x: 0, y: 0 }
        }
    },
})